var $,
    layer,
    form,
    table,
    loc = location.href,
    n1 = loc.length,//地址的总长度
    n2 = loc.indexOf('='),//取得=号的位置
    courseId = decodeURI(loc.substr(n2 + 1, n1 - n2));

layui.use(['jquery', 'table', 'layer', 'form'], function () {
    var $ = layui.jquery,
        layer = layui.layer,
        form = layui.form,
        table = layui.table;
});

getTableData();
function getTableData(id, courseName, updateDate) {
    console.log(courseId)
    if (courseId != null && courseId > 0) {
        $.ajax({
            url:'/Course/getCourseJournal',
            dataType: 'json',
            data: {
                'id' : id,
                'courseName' : courseName,
                'updateDate' : updateDate,
                'courseId' : courseId,
                'type' : 2
            },
            success: function (item) {
                getTable(item.data);
            }
        });
    } else {
        $.ajax({
            url:'/Course/getCourseJournal',
            dataType: 'json',
            data: {
                'id' : id,
                'courseName' : courseName,
                'updateDate' : updateDate,
                'type' : 2
            },
            success: function (item) {
                getTable(item.data);
            }
        });
    }
};

function getTable(data) {

    layui.use(['table'], function () {
        table = layui.table;

        table.render({
            elem: '#demo',
            data: data,
            page:true,
            limit:10,
            text: {
                none: '暂无相关数据' //默认：无数据。
            },
            cols:[[
                {checkbox:true},
                {align: '', title: '序号', align: 'center', templet:function (item) {
                        return item.LAY_INDEX;
                    }},
                {field:'id',title:'课程编号',align:'center',height:'20px'},
                {field:'courseId',title:'课程ID',align:'center',height:'20px'},
                {field:'courseName',title:'课程名称',align:'center',height:'20px'},
                {field:'coursePrice', title: '课程原价', align:'center'},
                {field:'courseNprice',title:'课程现价',align:'center'},
                {field:'updateDate',title:'操作时间',align:'center'}
            ]]
        });
    });
};

//搜索
function selProduct () {

    layui.use(['form'], function () {
        form = layui.form;
        var val = form.val('formDemo');
        getTableData(val.id, val.courseName, val.updateDate)
    });
}

//刷新
function refresh () {
    location.reload();
}

//返回首页
function backOff(){
    parent.jumpSystemHome();
}
